package cn.buk.qms.service;

import cn.buk.tms.dao.CustomerDao;
import cn.buk.tms.dao.PassengerDao;
import cn.buk.tms.entity.misc.Passenger;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: yfdai
 * Date: 13-8-29
 * Time: 下午9:37
 * To change this template use File | Settings | File Templates.
 */
public class PassengerServiceImpl implements PassengerService {

    private PassengerDao passengerDao;
    private CustomerDao customerDao;

    @Override
    public int create(Passenger passenger) {
        if (passenger == null) {
          return -2;
        } else if (passenger.getEnterpriseId()<=0) {
          return -3;
        } else if (passenger.getNameCn().trim().length() < 2) {
          return -4;
        } else {
          return passengerDao.create(passenger);
        }
    }

    @Override
    public Passenger getById(int id, int enterpriseId) {
        Passenger passenger = passengerDao.getById(id);
        if (passenger != null && passenger.getEnterpriseId() == enterpriseId) {
            return passenger;
        } else {
            return null;
        }
    }

    @Override
    public int update(Passenger passenger) {
        return passengerDao.update(passenger);
    }

    @Override
    public int delete(Passenger passenger) {
        if (passenger == null) {
          return -2;
        }

        return passengerDao.delete(passenger);
    }

    @Override
    public List<Passenger> getAll(int enterpriseId) {
        return  passengerDao.getAll(enterpriseId);
    }

    public PassengerDao getPassengerDao() {
        return passengerDao;
    }

    public void setPassengerDao(PassengerDao passengerDao) {
        this.passengerDao = passengerDao;
    }

    public CustomerDao getCustomerDao() {
        return customerDao;
    }

    public void setCustomerDao(CustomerDao customerDao) {
        this.customerDao = customerDao;
    }
}
